_base_ = 'base.py'
model = dict(
    type='GroupRCNN',
    backbone=dict(type='ResNet',
                  depth=50,
                  num_stages=4,
                  out_indices=(0, 1, 2, 3),
                  frozen_stages=1,
                  norm_cfg=dict(type='BN', requires_grad=True),
                  norm_eval=True,
                  style='pytorch',
                  init_cfg=dict(type='Pretrained',
                                checkpoint='torchvision://resnet50')),
    neck=dict(type='FPN',
              in_channels=[256, 512, 1024, 2048],
              out_channels=256,
              start_level=1,
              add_extra_convs='on_input',
              num_outs=5),
    rpn_head=dict(type='RetinaHead',
                  num_classes=80,
                  in_channels=256,
                  stacked_convs=4,
                  feat_channels=256,
                  anchor_generator=dict(type='AnchorGenerator',
                                        octave_base_scale=4,
                                        scales_per_octave=3,
                                        ratios=[0.5, 1.0, 2.0],
                                        strides=[8, 16, 32, 64, 128]),
                  bbox_coder=dict(type='DeltaXYWHBBoxCoder',
                                  target_means=[.0, .0, .0, .0],
                                  target_stds=[1.0, 1.0, 1.0, 1.0]),
                  loss_cls=dict(type='FocalLoss',
                                use_sigmoid=True,
                                gamma=2.0,
                                alpha=0.25,
                                loss_weight=1.0),
                  loss_bbox=dict(type='L1Loss', loss_weight=1.0)),
    roi_head=dict(type='GroupRoIHead',
                  num_stages=3,
                  stage_loss_weights=[1, 0.5, 0.25],
                  bbox_roi_extractor=dict(type='SingleRoIExtractor',
                                          roi_layer=dict(type='RoIAlign',
                                                         output_size=7,
                                                         sampling_ratio=0),
                                          out_channels=256,
                                          featmap_strides=[8, 16, 32, 64]),
                  bbox_head=[
                      dict(type='Shared2FCBBoxHead',
                           in_channels=256,
                           fc_out_channels=1024,
                           roi_feat_size=7,
                           num_classes=80,
                           bbox_coder=dict(type='DeltaXYWHBBoxCoder',
                                           target_means=[0.0, 0.0, 0.0, 0.0],
                                           target_stds=[0.1, 0.1, 0.2, 0.2]),
                           reg_class_agnostic=True,
                           loss_cls=dict(type='CrossEntropyLoss',
                                         use_sigmoid=False,
                                         loss_weight=1.0),
                           loss_bbox=dict(type='SmoothL1Loss',
                                          beta=1.0,
                                          loss_weight=1.0)),
                      dict(type='Shared2FCBBoxHead',
                           in_channels=256,
                           fc_out_channels=1024,
                           roi_feat_size=7,
                           num_classes=80,
                           bbox_coder=dict(type='DeltaXYWHBBoxCoder',
                                           target_means=[0.0, 0.0, 0.0, 0.0],
                                           target_stds=[0.05, 0.05, 0.1, 0.1]),
                           reg_class_agnostic=True,
                           loss_cls=dict(type='CrossEntropyLoss',
                                         use_sigmoid=False,
                                         loss_weight=1.0),
                           loss_bbox=dict(type='SmoothL1Loss',
                                          beta=1.0,
                                          loss_weight=1.0)),
                      dict(type='Shared2FCBBoxHead',
                           in_channels=256,
                           fc_out_channels=1024,
                           roi_feat_size=7,
                           num_classes=80,
                           bbox_coder=dict(
                               type='DeltaXYWHBBoxCoder',
                               target_means=[0.0, 0.0, 0.0, 0.0],
                               target_stds=[0.033, 0.033, 0.067, 0.067]),
                           reg_class_agnostic=True,
                           loss_cls=dict(type='CrossEntropyLoss',
                                         use_sigmoid=False,
                                         loss_weight=1.0),
                           loss_bbox=dict(type='SmoothL1Loss',
                                          beta=1.0,
                                          loss_weight=1.0))
                  ]),
    train_cfg=dict(rpn=dict(assigner=dict(type='MaxIoUAssigner',
                                          pos_iou_thr=0.5,
                                          neg_iou_thr=0.4,
                                          min_pos_iou=0,
                                          ignore_iof_thr=-1),
                            allowed_border=-1,
                            pos_weight=-1,
                            debug=False),
                   rpn_proposal=None,
                   rcnn=None),
    # only used to evaluate the rpn results
    # do not be adopted when generate the proposals for second stage.
    test_cfg=dict(rpn=dict(nms_pre=1000,
                           max_per_img=100,
                           nms=dict(type='nms', iou_threshold=0.5),
                           score_thr=0.05,
                           min_bbox_size=0),
                  rcnn=None))
data = dict(test=dict(type='PointCocoDataset',
                      ann_file='data/coco/annotations/instances_val2017.json',
                      img_prefix='data/coco/val2017/',
                      pipeline=[
                          dict(type='LoadImageFromFile'),
                          dict(type='LoadAnnotations', with_bbox=True),
                          dict(type='MultiScaleFlipAug',
                               img_scale=(1333, 800),
                               flip=False,
                               transforms=[
                                   dict(type='Resize', keep_ratio=True),
                                   dict(type='RandomFlip'),
                                   dict(type='Normalize',
                                        mean=[123.675, 116.28, 103.53],
                                        std=[58.395, 57.12, 57.375],
                                        to_rgb=True),
                                   dict(type='Pad', size_divisor=32),
                                   dict(type='DefaultFormatBundle'),
                                   dict(type='Collect',
                                        keys=['img', 'gt_bboxes', 'gt_labels'])
                               ])
                      ]))
